#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int inf = 0x7fffffff;
int N, M, x, y, z;
struct node
{
    int to, val;
    node(int to = 0, int val = inf) : to(to), val(val){};
    bool operator<(const node b) const { return this->val > b.val; }
};
int main()
{
    cin >> N >> M;
    vector<vector<int>> edge(N + 1, vector<int>(N + 1, inf));
    vector<bool> chosen(N + 1, false);
    priority_queue<node> que;
    for (int i = 0; i < M; ++i)
    {
        cin >> x >> y >> z;
        edge[x][y] = min(edge[x][y], z);
        edge[y][x] = edge[x][y];
    }
    int u = 1, csum = 0;
    que.push(node(u, 0));
    chosen[0] = true;
    while (que.empty() == false)
    {
        node nd = que.top();
        que.pop();
        if (chosen[nd.to] == true)
            continue;
        csum += nd.val;
        chosen[nd.to] = true;
        for (int i = 1; i <= N; ++i)
        {
            if (edge[nd.to][i] != inf && chosen[i] == false)
                que.push(node(i, edge[nd.to][i]));
        }
    }
    for (int i = 1; i <= N; ++i)
    {
        if (chosen[i] == false)
        {
            cout << "orz" << endl;
            return 0;
        }
    }
    cout << csum << endl;

    return 0;
}